package com.woniu.woniuproject.web;

import com.woniu.woniuproject.entity.Account;
import com.woniu.woniuproject.entity.User;
import com.woniu.woniuproject.entity.looselabel_record;
import com.woniu.woniuproject.service.AccountService;
import com.woniu.woniuproject.service.Looselabel_recordService;
import com.woniu.woniuproject.utils.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * 功能描述:<br>
 * 〈〉
 *
 * @author 徐威
 * @create 2020/11/25
 * @since 1.0.0
 */
@Controller
@RequestMapping("looselabel_record")
public class looselabel_recordController {
    @Autowired
    Looselabel_recordService looselabel_recordService;
    @RequestMapping("/queryalls")
    public String queryLooselabel_record(HttpServletRequest request, Map map){
        User user = (User) request.getSession().getAttribute("loginUser");
        List<looselabel_record> listtrue =  looselabel_recordService.queryisReturnedtrue(0,user.getId());
        List<looselabel_record> listfolse=  looselabel_recordService.queryisReturnedtrue(1,user.getId());
        if (listtrue!=null){
            map.put("listtrue",listtrue);
        }
        if (listfolse!=null){

            map.put("listfolse",listfolse);
        }
        return "monthrepays.html";
    }
    @Autowired
    AccountService accountService;
    @RequestMapping("/payment")
    @ResponseBody
    public ResponseResult<Object> payment(int ids,HttpServletRequest request){
            int code  = 500;
            String msg = "系统超时";
          User user = (User) request.getSession().getAttribute("loginUser");
        Account account = accountService.queryByUserId(user.getId());
        looselabel_record looselabel_records = looselabel_recordService.queryBykey(ids);
        if (account.getBalance()<looselabel_records.getReceivableMoney()){
             return  new ResponseResult<>(500,"账户可用余额不足，请充值");
        }

     int rew =  looselabel_recordService.payment(ids,user.getId());
        if (rew>0){
           code  = 200;
           msg = "还款成功";
        }
        return  new ResponseResult<>(code,msg);
        }
}
